import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

import Layout from '@/layout';

//静态路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'el-icon-house' }
    }]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]

//动态路由
export const asyncRoutes = [
  {
    path: '/memory',
    component: Layout,
    redirect: '/memoryImport',
    children: [
      {
        path: '/memoryImport',
        name: 'memoryImport',
        component: () => import('@/views/memoryImport/index.vue'),
        meta: { title: '内存条基表导入', icon: 'el-icon-tickets', keepAlive:false }
      }
    ]
  },
  {
    path:"/productOrder",
    component:Layout,
    redirect:"/productOrderImport",
    children:[
      {
        path:"/productOrderImport",
        name:"ProductOrderImport",
        component: () => import("@/views/productOrderImport/index.vue"),
        meta:{ title:"散件排产订单导入", icon:"el-icon-document" , keepAlive:false}
      }
    ]
  },
  {
    path:'/replacement',
    component: Layout,
    redirect: '/replacementVerify',
    children:[
      {
        path:"/replacementVerify",
        name:"replacementVerify",
        component: () => import ("@/views/replacementVerify/index.vue"),
        meta:{title:"散备件校验", icon:"el-icon-notebook-1", keepAlive:true}
      }
    ]
  },
  {
    path:'/consistency',
    component: Layout,
    redirect: '/consistencyVerify',
    children:[
      {
        path:"/consistencyVerify",
        name:"ConsistencyVerify",
        component: () => import ("@/views/consistencyVerify/index.vue"),
        meta:{title:"一致性校验", icon:"el-icon-notebook-2", keepAlive:true}
      }
    ]
  },
  {
    path:'/setting',
    component: Layout,
    redirect: '/userSetting',
    children:[
      {
        path:"/userSetting",
        name:"UserSetting",
        component: () => import ("@/views/inspectorInfo/index.vue"),
        meta:{title:"质检员设置", icon:"el-icon-user", keepAlive:false}
      }
    ]
  },
  {
    path:'/rpa',
    component: Layout,
    redirect: '/rpaTable',
    children:[
      {
        path:"/rpatable",
        name:"Rpatable",
        component: () => import ("@/views/rpaTable/index.vue"),
        meta:{title:"RPA查看IP", icon:"el-icon-connection", keepAlive:false}
      }
    ]
  },
  {
    path:"/user",
    component:Layout,
    redirect:"/userList",
    meta:{title:"用户管理", icon:"el-icon-s-grid"},
    children:[
      {
        path:"/userList",
        name:"userList",
        component: () => import("@/views/userList/index.vue"),
        meta:{ title:"用户信息", icon:"el-icon-user-solid" , keepAlive:false}
      },
      {
        path:"/rolePermission",
        name:"userPermission",
        component: () => import("@/views/userPermission/index.vue"),
        meta:{title:"角色权限",icon:"el-icon-s-operation",keepAlive:false}
      }
    ]
  },
];

//错误路由
export const errorRoutes = [
  { path: '*', redirect: '/404', hidden: true }
];

const createRouter = () => new Router({
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter();


export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher;
}

export default router
